<template>
  <div id="return_point_activityGood">
    <c-title :hide="false" text="活动商品"></c-title>
    <van-search v-model="keyword" shape="round" placeholder="请输入搜索关键词" @search="onSearch" />
    <div class="goodNum">商品数量：{{ goodsTotal }}</div>
    <div class="list" v-for="item in listData" :key="item.goods_id">
      <div class="list_time">{{ item.time }}</div>
      <div class="goodDetail">
        <img :src="item.thumb" class="goodDetail_img" alt="" />
        <div class="goodDetail_r">
          <div class="goodDetail_r_title">{{ item.title }}</div>
          <div class="goodDetail_r_b">
            <div class="goodDetail_r_b_price">¥ {{ item.price }}</div>
            <div class="goodDetail_r_b_sku flex">
              <div class="sku">库存：{{ item.stock }}</div>
              <div class="sku">销量：{{ item.sales }}</div>
            </div>
          </div>
        </div>
      </div>
      <div class="lis_tag">
        <div class="lis_tag_txt">{{ item.activity_name }}</div>
        <div class="lis_tag_txt">{{ item.category_name }}</div>
      </div>
    </div>
    <div class="pos set-pc-style">
      <div class="btn" @click="toAddGood">新增商品</div>
    </div>
  </div>
</template>
<script>
import { scrollMixin } from "utils/mixin";
export default {
  mixins: [scrollMixin], //加载更多
  data() {
    return {
      keyword: "",
      listData: [],
      goodsTotal: 0,

      page: 1, //分页数，当前页数
      isLoadMore: true, //判断是否要加载更多的标志
      total_page: 0 //总页数
    };
  },
  activated() {
    this.init();
    this.getData();
  },
  methods: {
    onSearch() {
      this.init();
      this.getData();
    },
    toAddGood() {
      if (this.$route.query.storeTag == 1) {
        this.$router.push(this.fun.getUrl("return_point_activityGoodAdd", {}, { storeTag: 1 }));
        return;
      }
      this.$router.push(this.fun.getUrl("return_point_activityGoodAdd", {}));
    },
    init() {
      this.listData = [];
      this.page = 1;
      this.total_page = 0;
      this.isLoadMore = true;
    },
    async getData() {
      let urlStr = "plugin.return-point.frontend.supplier.activity-goods.index";
      if (this.$route.query.storeTag == 1) {
        urlStr = "plugin.return-point.frontend.store.activity-goods.index";
      }
      let { data, msg, result } = await $http.post(urlStr, { page: this.page, keyword: this.keyword }, ".");
      if (result) {
        this.listData = data.data;
        this.total_page = data.last_page;
        this.isLoadMore = true;
        this.goodsTotal = data.total;
      } else {
        this.$toast(msg);
      }
    },
    async getMoreData() {
      if (!this.isLoadMore) return;
      this.isLoadMore = false;
      if (this.page >= this.total_page) {
      } else {
        let urlStr = "plugin.return-point.frontend.supplier.activity-goods.index";
        if (this.$route.query.storeTag == 1) {
          urlStr = "plugin.return-point.frontend.store.activity-goods.index";
        }
        this.page = this.page + 1;
        let json = {
          page: this.page,
          keyword: this.keyword
        };
        let { data, msg, result } = await $http.post(urlStr, json, ".");
        this.isLoadMore = true;
        if (result) {
          this.listData = this.listData.concat(data.data);
        } else {
          this.page = this.page - 1;
          this.isLoadMore = false;
          this.$toast(msg);
        }
      }
    }
  }
};
</script>
<style lang="scss" scoped>
#return_point_activityGood {
  padding-bottom: 5rem;
  .pos {
    position: fixed;
    width: 100%;
    bottom: 0;
    left: 0;
    background: #ffffff;
    .btn {
      margin: 0.63rem 0.75rem;
      text-align: center;
      font-weight: 500;
      font-size: 0.94rem;
      line-height: 1;
      background: #f15353;
      border-radius: 1.28rem;
      color: #ffffff;
      padding: 0.75rem 0;
      box-sizing: border-box;
    }
  }
  .goodNum {
    margin: 0.88rem 1.06rem;
    text-align: left;
    font-weight: 500;
    font-size: 0.88rem;
    line-height: 1rem;
    margin-bottom: 1rem;
  }
  .list {
    margin: 0 0.75rem;
    margin-bottom: 0.63rem;
    background: #ffffff;
    border-radius: 0.5rem;
    padding: 0.94rem 0.75rem;
    text-align: left;
    .lis_tag {
      display: flex;
      flex-wrap: wrap;
      font-size: 0.75rem;
      line-height: 1;
      margin-top: 0.63rem;
      .lis_tag_txt {
        padding: 0.37rem 0.53rem;
        box-sizing: border-box;
        background: #f5f5f5;
        border-radius: 0.38rem;
        margin-right: 0.5rem;
      }
    }
    .list_time {
      font-weight: 500;
      font-size: 0.88rem;
      margin-bottom: 1rem;
    }
    .goodDetail {
      display: flex;
      .goodDetail_img {
        flex-shrink: 0;
        margin: 0;
        margin-right: 0.53rem;
        background: #d6d6dc;
        border-radius: 0.63rem;
        width: 5.38rem;
        height: 5.38rem;
      }
      .goodDetail_r {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        .goodDetail_r_title {
          font-weight: 500;
          font-size: 0.88rem;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        .goodDetail_r_b {
          display: flex;
          flex-direction: column;
          .goodDetail_r_b_price {
            font-weight: bold;
            font-size: 0.88rem;
            color: #f15353;
          }
          .goodDetail_r_b_sku {
            font-size: 0.81rem;
            color: #00001c;
            .sku:first-child {
              margin-right: 0.97rem;
            }
          }
        }
      }
    }
  }
}
</style>
